range: Fix trough clickability
authorMatthias Clasen <mclasen@redhat.com>
Fri, 11 Mar 2016 06:27:21 +0000 (01:27 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 11 Mar 2016 06:27:21 +0000 (01:27 -0500)
We previously considered any click inside the trough if it
hit an area that the slider might cover. Bring this behavior
back; the trough of scales is otherwise just too narrow to
hit easily with a click.

gtk/gtkrange.c

index b9fada2dc74c21b9256efa401a79be6aa533b277..50357c2cb69974bd6a9cdc2c2974148e783cecd7 100644 (file)
@@ -3429,6 +3429,15 @@ gtk_range_move_slider (GtkRange     *range,
     gtk_widget_error_bell (GTK_WIDGET (range));
 }
 
+static gboolean
+rectangle_contains_point (GdkRectangle *rect,
+                          gint          x,
+                          gint          y)
+{
+  return (x >= rect->x) && (x < rect->x + rect->width) &&
+         (y >= rect->y) && (y < rect->y + rect->height);
+}
+
 /* Update mouse location, return TRUE if it changes */
 static void
 gtk_range_update_mouse_location (GtkRange *range)
@@ -3437,12 +3446,17 @@ gtk_range_update_mouse_location (GtkRange *range)
   gint x, y;
   MouseLocation old;
   GtkWidget *widget = GTK_WIDGET (range);
+  GdkRectangle trough_alloc, slider_alloc, slider_trace;
 
   old = priv->mouse_location;
 
   x = priv->mouse_x;
   y = priv->mouse_y;
 
+  gtk_css_gadget_get_border_box (priv->trough_gadget, &trough_alloc);
+  gtk_css_gadget_get_border_box (priv->slider_gadget, &slider_alloc);
+  gdk_rectangle_union (&slider_alloc, &trough_alloc, &slider_trace);
+
   if (priv->grab_location != MOUSE_OUTSIDE)
     priv->mouse_location = priv->grab_location;
   else if (priv->stepper_a_gadget &&
@@ -3459,7 +3473,7 @@ gtk_range_update_mouse_location (GtkRange *range)
     priv->mouse_location = MOUSE_STEPPER_D;
   else if (gtk_css_gadget_border_box_contains_point (priv->slider_gadget, x, y))
     priv->mouse_location = MOUSE_SLIDER;
-  else if (gtk_css_gadget_border_box_contains_point (priv->trough_gadget, x, y))
+  else if (rectangle_contains_point (&slider_trace, x, y))
     priv->mouse_location = MOUSE_TROUGH;
   else if (gtk_css_gadget_margin_box_contains_point (priv->gadget, x, y))
     priv->mouse_location = MOUSE_WIDGET;